<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>设置计算属性</title>
    <script src="https://cdn.bootcss.com/vue/2.4.4/vue.js"></script>

</head>
<body>
  <h3>设置计算属性，同步更新元数据的值</h3>
  <div id="myApp">
    <p>新款iPhone8plus（256GB）售价为：{{price}}美元， 含税价格为：{{priceInTax}}美元，折合人民币：{{priceRMB}}元<br>
    <br>
      <button @click="btnClick(1000)">在澳门含税价格为1000美元</button>
      <br><small>点击后同步更新原售价和人民币价</small>
  </div>
 <script>
  var myApp = new Vue({
    el: '#myApp',
    data: {
      price: 949,
    },
    computed: {
      priceInTax:{
        get:function(){ 
           return Math.round(this.price * 1.08); 
        },
        set:function(value){
          this.price = Math.round( value / 1.08);
        }
      },
      priceRMB:function(){
        return Math.round(this.priceInTax * 6.15);
      }
    },
    methods:{
      btnClick:function(newPrice){
        this.priceInTax = newPrice;
      }
    }
  })
</script>
</body>
</html>